package com.ebring.shareEducation.service.impl;

import com.ebring.shareEducation.bean.PayOrder;
import com.ebring.shareEducation.dao.PayOrderMapper;
import com.ebring.shareEducation.service.PayOrderService;
import com.ebring.shareEducation.utils.RspMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PayOrderServiceImpl implements PayOrderService {
    @Autowired
    private PayOrderMapper payOrderMapper;

    @Override
    public RspMsg<PayOrder> insertPayOrder(PayOrder payOrder) {
        RspMsg rspMsg = new RspMsg();
       int i = payOrderMapper.insertSelective(payOrder);
       if (i>0){
           rspMsg.setOK();
           rspMsg.setMsg("保存成功");
       }else {
           rspMsg.setError();
           rspMsg.setMsg("保存失败");
       }
        return rspMsg;
    }

    /**
     *根据用户id 显示支付明细
     * @param userId
     * @return
     */
    @Override
    public RspMsg<PayOrder> selectPayOrderByUserid(String userId) {
        RspMsg rspMsg = new RspMsg();
        List<PayOrder> payOrders = payOrderMapper.selectPayOrderByUserid(userId);
        if (payOrders.size()>0){
            rspMsg.setOK();
            rspMsg.setResult(payOrders);
        }else{
            rspMsg.setError();
            rspMsg.setMsg("未找到数据");
        }

        return  rspMsg;
    }
}
